CString::operator =

const CString& operator =( const CString& stringSrc );
  throw( CMemoryException );
const CString& operator =( TCHAR ch );
  throw( CMemoryException );
const CString& operator =( const unsigned char* psz );
  throw( CMemoryException );
const CString& operator =( LPCWSTR lpsz );
  throw( CMemoryException );
const CString& operator =( LPCSTR lpsz );
  throw( CMemoryException );

说明:
这个CString赋值操作符(=)用新的数据来初始化一个已经存在的CString对象。如果目标字符串(即左边的字符串)已经具有足够大的空间来保存新数据,则不用进行新的内存分配。不管你什么时候使用这个赋值操作符,都要小心可能出现的内存异常,因为常常要为保存新的结果给CString对象分配内存。

示例:
下面的例子说明了如何使用CString::operator =。
// CString::operator =示例:
CString s1, s2; // 空的CString对象
s1 = "cat"; // s1 = "cat"
s2 = s1; // s1 and s2 each = "cat"
s1 = "the " + s1; // 或者是表达式
s1 = 'x'; // 或者只是单个的字符

请参阅:CString::CString